package easy;

public class Solution_495 {

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int count = 0, end = 0;
        for (int timeSery : timeSeries) {
            if (timeSery <= end) {
                // 还在中毒
                // 中毒时间 - （当前时间 - 上一次中毒的结束时间）
                count += duration - (end - timeSery);
            } else {
                // 不在中毒
                count += duration;
            }
            end = timeSery + duration;
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_495 model = new Solution_495();
        System.out.println(model.findPoisonedDuration(new int[]{1, 4}, 2));
        System.out.println(model.findPoisonedDuration(new int[]{1, 2}, 2));
        System.out.println(model.findPoisonedDuration(new int[]{89,231,368,841,1054,1258,1760,2216,2236,2243,2412,2780,2973,3326,3605,3966,4311,4565,4848,5001,5263,5538,6059,6121,6587,7059,7455,7727,8103,8514,8851,9075,9542,9569,9787,9884,10232,10240,10462,10637,11158,11447,11891,12193,12426,12885,12895,13024,13374,13757,13934,14428,14856,15224,15633,15856,16165,16380,16693,16955,17011,17276,17706,17942,18295,18688,19142,19471,19834,20073,20356,20870,21316,21469,21521,21764,21930,22352,22534,22772,23013,23386,23548,23664,23982,24218,24656,25114,25258,25558,25771,26176,26617,26687,27058,27176,27341,27401,27637,28157,28399,28608,29002,29179,29426,29603,29696,29912,30306,30429,30476,30760,31229,31726,32066,32569,33009,33045,33504,33684,33876,34188,34579,34693,34880,35279,35290,35801,36116,36286,36621,36767,37114,37613,37849,37937,38241,38572,38658,39073,39447,39501,39952,40461,40895,41144,41455,41910,42227,42425,42735,42949,43046,43309,43534,44009,44031,44114,44570,44923,45163,45339,45775,46014,46082,46328,46447,46595,46700,46916,47430,47804,48167,48494,48899,48940,49235,49371,49803,50150,50305,50535,50995,51267,51312,51453,51767,52161,52537,52722,53090}, 1000000));
    }
}
